/**
 * 结算确认
 */

import Taro from "@tarojs/taro";
import { View } from "@tarojs/components";
import FormInput from "@/components/common/FormInput";
import ByButton from "@/components/ui/ByButton";
import ByPopupBottom, {
  ByPopupBottomEvent,
} from "@/components/ui/ByPopupBottom";

import useForm from "@/hooks/useForm";
import ApiBalance from "@/api/balance";

export default ({
  intentCustomerId,
  onCancel,
}: {
  intentCustomerId: number;
} & ByPopupBottomEvent) => {
  const { loading, model, setModel, submit } = useForm(
    ApiBalance.balanceConfirm,
    {
      defaultModel: { intentCustomerId, remark: "" },
      onSuccess() {
        Taro.showToast({ title: "操作成功！" });
        Taro.navigateTo({
          url: "/packageProject/pages/engineeringFunds/apply?specialCode=fk4",
        });
      },
    }
  );

  return (
    <ByPopupBottom title="项目经理确认" onCancel={onCancel}>
      <View className="py-4 text-sm text-center">
        本项目金额明细无误，您可以确认后申请工程付款
      </View>

      <View className="px-4 m-3">
        <FormInput
          type="textarea"
          value={model.remark}
          placeholder="您可输入备注"
          onChange={(e) => setModel({ remark: e })}
        />
      </View>

      <ByButton
        size="large"
        loading={loading}
        className="mt-6 mb-3 w-2/3"
        onClick={() => submit()}
      >
        确认并申请付款
      </ByButton>
    </ByPopupBottom>
  );
};
